package com.cl.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cl.entity.BanjiEntity;
import com.cl.service.BanjiService;
import com.cl.utils.PageUtils;
import com.cl.utils.R;

/**
 * 班级
 */
@RestController
@RequestMapping("/banji")
public class BanjiController {
    @Autowired
    private BanjiService banjiService;
    
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = banjiService.queryPage(params);
        return R.ok().put("page", page);
    }
    
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        BanjiEntity banji = banjiService.selectById(id);
        return R.ok().put("data", banji);
    }
    
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BanjiEntity banji){
        banji.setChuangjianshijian(new Date());
        banjiService.insert(banji);
        return R.ok();
    }
    
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BanjiEntity banji){
        banjiService.updateById(banji);
        return R.ok();
    }
    
    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        banjiService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
} 